package com.czmini.cztest.controller;

import com.czmini.cztest.common.TokenDb;
import com.czmini.cztest.config.UserBaseStr;
import com.czmini.cztest.dto.AllureReportDto;
import com.czmini.cztest.dto.ResultDto;
import com.czmini.cztest.dto.TokenDto;
import com.czmini.cztest.service.ZcTesReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Objects;

/**
 * @ProjectName: cztest
 * @Package: com.czmini.cztest.controller
 * @ClassName: ZcTesReportController
 * @Author: 还是那个橙子
 * @Description: 报告管理
 * @Date: 2022/5/14 22:21
 * @Version: 1.0
 */
@Slf4j
@Api(tags = "zctest-报告管理")
@RestController
@RequestMapping("/report")
public class ZcTesReportController {


    @Autowired
    private ZcTesReportService zcTesReportService;

    @Autowired
    private TokenDb tokenDb;


    @ApiOperation(value = "获取allure报告")
    @GetMapping("/allureReport/{taskId}")
    public ResultDto<AllureReportDto> getAllureReport(HttpServletRequest request,@PathVariable  Integer taskId){
        log.info("获取allure报告"+taskId);
        if (Objects.isNull(taskId)) {
            return ResultDto.success("任务id不能为空");
        }
        TokenDto tokenDto = tokenDb.getTokenDto(request.getHeader(UserBaseStr.LOGIN_TOKEN));
        ResultDto<AllureReportDto> resultDto = zcTesReportService.getAllureReport(tokenDto, taskId);
        return resultDto;
    }






}



